package reference;

/**
 * @author ZhuQi
 * @ClassName StrongReference
 * @Date 2022/9/23 10:51
 * @Version 1.0
 * @Description 测试强引用，
 * 强引用，就算系统OOM 也不会回收
 *
 * 这里根据根可达法，引用置为 null 再显示调用GC 将其回收
 */
public class StrongReferenceDemo {

    public static void main(String[] args) {
        StrongObj strongObj = new StrongObj();
        // reference.StrongObj@7ef20235
        System.out.println(strongObj);

        strongObj = null;
        System.gc();
        // null
        System.out.println(strongObj);
    }
}
class StrongObj{
    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("finalize------------------------");
    }
}